﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Institutions</title>

    <link href="@Url.Content("~/Content/StyleSheet.css")" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="@Url.Content("~/Scripts/themes/default/easyui.css")" />
	<link rel="stylesheet" type="text/css" href="@Url.Content("~/Scripts/themes/icon.css")" />
    @*<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />*@
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")"  type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.easyui.min.js")" type="text/javascript" ></script>
    <script type="text/javascript">
        $(function () {

            var industryJson = null;
            var categoryJson = null;
            $.ajax({
                url: '@Url.Action("GetMetaData","Database")',   // 指定调用的URL，对应于Controller  
                data: '{}',                             // 如果请求有参数，需要在这里指定  
                type: "POST",                           // 请求类型  
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {              // 请求成功后的回调  
                    if (data == null || data.length == 0) {
                        return false;
                    } else {

                        for (var i = 0; i < data.length; i++) {
                            //alert(data[i].items);
                            if (data[i].name == "identity") {
                                industryJson = data[i].items;
                                $('#cboIndustry').combobox({
                                    //url: '@Url.Action("GetIndustry","Database")',
                                    data: industryJson,
                                    mode: "local",
                                    editable: false,
                                    valueField: 'id', //'id',
                                    textField: 'text'//'text'
                                });
                            }
                            if (data[i].name == "education") {
                                categoryJson = data[i].items;
                                $('#cboCategory').combobox({
                                    //url: categoryJson, //'@Url.Action("GetCategory","Database")',
                                    data: categoryJson, //'@Url.Action("GetCategory","Database")',
                                    mode: "local",
                                    valueField: 'id',
                                    textField: 'text'
                                });
                            }
                            //alert(item.name);
                        }
                        //writeMsg(data);
                    }
                },
                error: function (data) {                // 请求失败后的回调  
                    alert(data.statusText);
                }
            });

            //            $('#cboIndustry').combobox({
            //                //url: '@Url.Action("GetIndustry","Database")',
            //                data: industryJson,
            //                mode: "local",
            //                editable: false,
            //                valueField: 'id', //'id',
            //                textField: 'text'//'text'
            //            });
            //            $('#cboCategory').combobox({
            //                //url: categoryJson, //'@Url.Action("GetCategory","Database")',
            //                data: categoryJson, //'@Url.Action("GetCategory","Database")',
            //                mode: "local",
            //                valueField: 'id',
            //                textField: 'text'
            //            });
            //            alert(document.body.offsetWidth);
            //            alert(document.body.offsetHeight);
            //            //alert($(document.body).height());document.body.offsetHeight - 26,
            //            alert(screen.width);window.parent.document.documentElement.innerHTML
            //            alert(window.parent);document.body.scrollHeight
            //alert($(window.parent.document.getElementById("mainPanle")).height()); 
            //alert('@Url.Action("InstitutionPaged","Database")');
            $('#tblInstitution').datagrid({
                url: '@Url.Action("InstitutionPaged","Database", new {pageIndex = 0})',
                title: '单位列表',
                width: document.body.offsetWidth - 10,
                height: $(window.parent.document.getElementById("mainPanle")).height() - 156,
                fitColumns: true,
                nowrap: false,
                loadMsg: "数据加载中，请稍后……",
                pagination: true,
                pageSize: 20,
                columns: [[
					{ field: 'ID', title: 'Item ID', width: 120 },
					{ field: 'Name', title: '单位名称', width: 100 },
                //					{ field: 'listprice', title: 'List Price', width: 80, align: 'right',
                //					    styler: function (value, row, index) {
                //					        if (value < 20) {
                //					            return 'background-color:#ffee00;color:red;';
                //					        }
                //					    }
                //					},
                //{ field: 'status', title: 'Status', width: 60, align: 'center' },
					{field: 'Industry', title: '单位行业', width: 120, align: 'right' },
					{ field: 'Category', title: '单位性质', width: 100 }

				]],
                rowStyler: function (index, row, css) {
                    //                    if (row.listprice > 80) {
                    //                        return 'background-color:#6293BB;color:#fff;font-weight:bold;';
                    //                    }
                }
            });

            var pg = $("#tblInstitution").datagrid("getPager");
            if (pg) {
                $(pg).pagination({
                    onBeforeRefresh: function () {
                        alert('before refresh');
                    },
                    onRefresh: function (pageNumber, pageSize) {
                        alert(pageNumber);
                        alert(pageSize);
                    },
                    onChangePageSize: function () {
                        alert('pagesize changed');
                    },
                    onSelectPage: function (pageNumber, pageSize) {
                        //alert(pageNumber);
                        //alert(pageSize);
                        // ===============================

                        //                        var queryParams = $('#tblInstitution').datagrid('options').queryParams;
                        //                        queryParams.who = who.value;
                        //                        queryParams.type = type.value;
                        //                        queryParams.searchtype = searchtype.value;
                        //                        queryParams.keyword = keyword.value;
                        //重新加载datagrid的数据  
                        var url = '@Url.Action("InstitutionPaged","Database")';
                        url += "?pageIndex=" + pageNumber;
                        var opts = $('#tblInstitution').datagrid('options');
                        opts.url = url;
                        $("#tblInstitution").datagrid('reload');

                        // ================================

                    }
                });
            }

            // =============================
            $("#btnSearch").click(function () {
                //var url = '@Url.Action("InstitutionPaged","Database")';
                //url += "?pageIndex=" + pageNumber;
                var opts = $('#tblInstitution').datagrid('options');
                var queryParams = opts.queryParams;
                //opts.url = url;
                queryParams.industry = $('#cboIndustry').combobox('getValue');
                queryParams.category = $('#cboCategory').combobox('getValue');
                $("#tblInstitution").datagrid('reload');
            });

            // =============================
        });
    </script>

</head>
<body>

<div region="north" split="true" title="选择数据库">
	<table  id="tblSearch">
		<tr>
			<td>单位名称</td><td><input type="text" id="txtSrcConn" class="easyui-validatebox" /></td>
			<td>单位行业</td><td ><select id="cboIndustry"></select></td>
            <td></td>
		</tr>
		<tr>
			<td>单位XX</td><td><input type="text" id="txtDestConn"  class="easyui-validatebox" /></td>
			<td>单位性质</td><td><select id="cboCategory" ></select></td>
			<td><a href="javascript:void(0)" id="btnSearch" class="easyui-linkbutton"  iconCls="icon-ok">查找</a></td>
		</tr>
	</table>
	
</div>

<div region="center" style="overflow: scroll; padding: 10px" title="单位列表" id="divCompareResult">
 <table id="tblInstitution"></table>
</div>

   
</body>
</html>
